library(haven)
library(readr)
library(data.table)
library(scales)
library(dplyr)
library(lfe)
library(stargazer)
cohort <- fread("H:/Zheng_10223/Joint/cohort_aug26.csv")


#### FIGURE 2: COEF PLOT (absolute upward mobility) ####
## INDIVIDUAL
refugee <- cohort[which(cohort$ImmigrationCategory=="Refugee"),]
IGM_refugee <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$ImmigrationCategory=="Refugee"),])

IGM_age0_4 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$LANDING_AGE %in% c(0,1,2,3,4)),])
IGM_age5_9 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$LANDING_AGE %in% c(5,6,7,8,9)),])
IGM_age10_14 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$LANDING_AGE %in% c(10,11,12,13,14)),])
IGM_age15_17 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$LANDING_AGE %in% c(15,16,17)),])

IGM_english <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$AnyEnglish_Main==1),])
IGM_noenglish <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$AnyEnglish_Main==0),])

IGM_manager <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$IntendedOccupation_Main=="Managerial/Professional"),])
IGM_skilled <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$IntendedOccupation_Main=="Skilled and Technical"),])
IGM_clerical <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$IntendedOccupation_Main=="Clerical and Laborers"),])
IGM_newworker <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$IntendedOccupation_Main=="New Workers"),])
IGM_nonworker <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$IntendedOccupation_Main=="Non-Workers"),])

IGM_europe <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$WORLD_AREA_BIRTH=="Europe"),])
IGM_easternasia <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$WORLD_AREA_BIRTH=="Eastern Asia"),])
IGM_africa <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$WORLD_AREA_BIRTH=="Africa and Middle East"),])
IGM_southamerica <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$WORLD_AREA_BIRTH=="South and Central America"),])
IGM_southasia <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$WORLD_AREA_BIRTH=="Southern Asia"),])
IGM_oceania <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$WORLD_AREA_BIRTH=="Oceania and other Asia"),])

IGM_noenclave <-lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$enclave==0),])
IGM_enclave <-lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$enclave==1),])


IGM_toronto <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$DESTINATION_CMA=="Toronto"),])
IGM_montreal <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$DESTINATION_CMA=="Montreal"),])
IGM_vancouver <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$DESTINATION_CMA=="Vancouver"),])
IGM_calgary <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$DESTINATION_CMA=="Calgary"),])
IGM_edmonton <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$DESTINATION_CMA=="Edmonton"),])

output <- rbind(predict(IGM_refugee, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_age0_4, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_age5_9, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_age10_14, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_age15_17, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_noenglish, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_english, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_nonworker, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_newworker, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_clerical, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_skilled, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_manager, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_europe, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_southamerica, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_oceania, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_africa, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_southasia, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_easternasia, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_noenclave, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_enclave, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                
                predict(IGM_calgary, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
      
                predict(IGM_edmonton, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_vancouver, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_toronto, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                predict(IGM_montreal, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"))

write.csv(output,"H:/Zheng_10223/Joint/dfrefugeecoef.csv")

others <- cohort[which(!cohort$ImmigrationCategory=="Refugee"),]
IGM_others <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others)

IGM_age0_4 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$LANDING_AGE %in% c(0,1,2,3,4)),])
IGM_age5_9 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$LANDING_AGE %in% c(5,6,7,8,9)),])
IGM_age10_14 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$LANDING_AGE %in% c(10,11,12,13,14)),])
IGM_age15_17 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$LANDING_AGE %in% c(15,16,17)),])

IGM_english <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$AnyEnglish_Main==1),])
IGM_noenglish <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$AnyEnglish_Main==0),])

IGM_manager <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$IntendedOccupation_Main=="Managerial/Professional"),])
IGM_skilled <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$IntendedOccupation_Main=="Skilled and Technical"),])
IGM_clerical <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$IntendedOccupation_Main=="Clerical and Laborers"),])
IGM_newworker <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$IntendedOccupation_Main=="New Workers"),])
IGM_nonworker <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$IntendedOccupation_Main=="Non-Workers"),])

IGM_europe <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$WORLD_AREA_BIRTH=="Europe"),])
IGM_easternasia <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$WORLD_AREA_BIRTH=="Eastern Asia"),])
IGM_africa <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$WORLD_AREA_BIRTH=="Africa and Middle East"),])
IGM_southamerica <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$WORLD_AREA_BIRTH=="South and Central America"),])
IGM_southasia <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$WORLD_AREA_BIRTH=="Southern Asia"),])
IGM_oceania <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$WORLD_AREA_BIRTH=="Oceania and other Asia"),])


IGM_noenclave <-lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$enclave==0),])
IGM_enclave <-lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$enclave==1),])


IGM_toronto <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$DESTINATION_CMA=="Toronto"),])
IGM_montreal <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$DESTINATION_CMA=="Montreal"),])
IGM_vancouver <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$DESTINATION_CMA=="Vancouver"),])
IGM_calgary <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$DESTINATION_CMA=="Calgary"),])
IGM_edmonton <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$DESTINATION_CMA=="Edmonton"),])

output_others <- rbind(predict(IGM_others, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_age0_4, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_age5_9, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_age10_14, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_age15_17, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_noenglish, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_english, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_nonworker, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_newworker, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_clerical, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_skilled, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_manager, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_europe, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_southamerica, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_oceania, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_africa, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_southasia, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_easternasia, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_noenclave, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_enclave, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       
                       predict(IGM_calgary, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_edmonton, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_vancouver, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_toronto, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"),
                       predict(IGM_montreal, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=25), interval="confidence"))

# Portrait
par(mar=c(4,19,1,1)) # save as letter portrait
plot(x=output[,1], y=c(1, 3:6, 8:9, 11:15, 17:22, 24:25, 27:31), xlim=c(41,59), xlab="Child Rank | Parent=p25", ylab="", yaxt="n",  cex.lab=1.5, cex.axis=1.5,
     pch=c(19, 20,20,20,20, 23,23, 18,18,18,18,18, 15,15,15,15,15,15, 12,12, 17,17,17,17,17), cex=c(1.3,2,2,2,2,1.3,1.3,2,2,2,2,2,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3),
     col=c("black", rep("firebrick",4), rep("black", 2), rep("orange", 5), rep("forestgreen", 6),rep("purple",2), rep("royalblue3", 5)))
arrows(y0=c(1, 3:6, 8:9, 11:15, 17:22,24:25, 27:31), y1=c(1, 3:6, 8:9, 11:15, 17:22,24:25, 27:31), x0=output[,2], x1=output[,3], length=0, 
       col=c("black", rep("firebrick",4), rep("black", 2), rep("orange", 5), rep("forestgreen", 6),rep("purple",2), rep("royalblue3", 5)))
points(x=output_others[,1], y=c(1, 3:6, 8:9, 11:15, 17:22,24:25, 27:31), xlim=c(42,67),xlab="", ylab="", yaxt="n",  cex.lab=1.5, cex.axis=1.5,
       pch=c(19, 20,20,20,20, 23,23, 18,18,18,18,18, 15,15,15,15,15,15, 12,12, 17,17,17,17,17), cex=c(1.3,2,2,2,2,1.3,1.3,2,2,2,2,2,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3),
       col=c(alpha("black",0.3), rep(alpha("firebrick",0.3), 4), rep(alpha("black", 0.3), 2), rep(alpha("orange", 0.3), 5), rep(alpha("forestgreen", 0.3), 6), rep(alpha("purple", 0.3), 2), rep(alpha("royalblue3", 0.3), 5)))
arrows(y0=c(1, 3:6, 8:9, 11:15, 17:22,24:25, 27:31), y1=c(1, 3:6, 8:9, 11:15, 17:22,24:25, 27:31), x0=output_others[,2], x1=output_others[,3], length=0, 
       col=c(alpha("black",0.3), rep(alpha("firebrick",0.3), 4), rep(alpha("black", 0.3), 2), rep(alpha("orange", 0.3), 5), rep(alpha("forestgreen", 0.3), 6), rep(alpha("purple", 0.3), 2), rep(alpha("royalblue3", 0.3), 5)))

text(x=24.3, y=c(1, 3:6, 8:9, 11:15, 17:22, 24:25, 27:31), adj=0, cex=1.2,
     c("Overall", "Landing Age: 0-4", "Landing Age: 5-9", "Landing Age: 10-14", "Landing Age: 15-17",
       "Speak English? No", "Speak English: Yes", "Intended Occ. Non-Workers", "Intended Occ. New Workers", "Intended Occ. Clerical & Laborers","Intended Occ. Skilled & Technical",  "Intended Occ. Managerial & Professional",   
       "Birthplace: Europe", "Birthplace: South and Central America", "Birthplace: Oceania and other Asia", "Birthplace: Africa and Middle East", "Birthplace: Southern Asia", "Birthplace: Eastern Asia", "Minority Neighborhood: No","Minority Neighborhood: Yes",
       "Landing CMA: Calgary", "Landing CMA: Edmonton", "Landing CMA: Vancouver", "Landing CMA: Toronto", "Landing CMA: Montreal"), xpd=TRUE)
text(x=output[1,1], y=1.5, "Refugee")
text(x=output_others[1,1], y=1.5, "Non-Refugee", col=alpha("black", 0.4))

# Landscape:
par(mar=c(16,4.5,1,1))
plot(y=output[,1], x=c(1, 3:6, 8:9, 11:15, 17:22, 24:25, 27:31), ylim=c(41,59), ylab="Child Rank | Parent=p25", xlab="", xaxt="n",  cex.lab=1.5, cex.axis=1.5,
     pch=c(19, 20,20,20,20, 23,23, 18,18,18,18,18, 15,15,15,15,15,15, 12,12, 17,17,17,17,17), 
     cex=c(1.6,2.3,2.3,2.3,2.3,1.6,1.6,2.3,2.3,2.3,2.3,2.3,1.6,1.6,1.6,1.6,1.6,1.6,1.6,1.6,1.6,1.6,1.6,1.6),
     col=c("black", rep("firebrick",4), rep("black", 2), rep("orange", 5), rep("forestgreen", 6),rep("purple",2), rep("royalblue3", 5)))
arrows(x0=c(1, 3:6, 8:9, 11:15, 17:22,24:25, 27:31), x1=c(1, 3:6, 8:9, 11:15, 17:22,24:25, 27:31), y0=output[,2], y1=output[,3], length=0, 
       col=c("black", rep("firebrick",4), rep("black", 2), rep("orange", 5), rep("forestgreen", 6),rep("purple",2), rep("royalblue3", 5)))
points(y=output_others[,1], x=c(1, 3:6, 8:9, 11:15, 17:22,24:25, 27:31), xlab="", ylab="", xaxt="n",  cex.lab=1.5, cex.axis=1.5,
       pch=c(19, 20,20,20,20, 23,23, 18,18,18,18,18, 15,15,15,15,15,15, 12,12, 17,17,17,17,17), 
       cex=c(1.6,2.3,2.3,2.3,2.3,1.6,1.6,2.3,2.3,2.3,2.3,2.3,1.6,1.6,1.6,1.6,1.6,1.6,1.6,1.6,1.6,1.6,1.6,1.6),
       col=c(alpha("black",0.3), rep(alpha("firebrick",0.3), 4), rep(alpha("black", 0.3), 2), rep(alpha("orange", 0.3), 5), rep(alpha("forestgreen", 0.3), 6), rep(alpha("purple", 0.3), 2), rep(alpha("royalblue3", 0.3), 5)))
arrows(x0=c(1, 3:6, 8:9, 11:15, 17:22,24:25, 27:31), x1=c(1, 3:6, 8:9, 11:15, 17:22,24:25, 27:31), y0=output_others[,2], y1=output_others[,3], length=0, 
       col=c(alpha("black",0.3), rep(alpha("firebrick",0.3), 4), rep(alpha("black", 0.3), 2), rep(alpha("orange", 0.3), 5), rep(alpha("forestgreen", 0.3), 6), rep(alpha("purple", 0.3), 2), rep(alpha("royalblue3", 0.3), 5)))
axis(1, at=c(1, 3:6, 8:9, 11:15, 17:22, 24:25, 27:31), rep("", 25))
text(y=39, x=c(1, 3:6, 8:9, 11:15, 17:22, 24:25, 27:31), cex=1.5, srt=45, xpd=TRUE, pos=2,
     c("Overall", "Landing Age: 0-4", "Landing Age: 5-9", "Landing Age: 10-14", "Landing Age: 15-17",
       "Speak English? No", "Speak English: Yes", "Intended Occ. Non-Workers", "Intended Occ. New Workers", "Intended Occ. Clerical & Laborers","Intended Occ. Skilled & Technical",  "Intended Occ. Manag. & Prof.",   
       "Birthplace: Europe", "Birthplace: South & Central America", "Birthplace: Oceania and other Asia", "Birthplace: Africa and Middle East", "Birthplace: Southern Asia", "Birthplace: Eastern Asia", "Minority Neighborhood: No","Minority Neighborhood: Yes",
       "Landing CMA: Calgary", "Landing CMA: Edmonton", "Landing CMA: Vancouver", "Landing CMA: Toronto", "Landing CMA: Montreal"))
text(y=output[1,1]-1.8, x=1.5, "Refugee", srt=90, cex=1.4)
text(y=output_others[1,1]+2.5, x=1.5, "Non-Refugee", col=alpha("black", 0.4), srt=90, cex=1.4)



# COUNTS: FOR ALL THREE COEF PLOTS

# Landing Age:

# Refugees
length(which(cohort$ImmigrationCategory=="Refugee" & cohort$LANDING_AGE %in% c(0,1,2,3,4) ))
length(which(cohort$ImmigrationCategory=="Refugee" & cohort$LANDING_AGE %in% c(5,6,7,8,9) ))
length(which(cohort$ImmigrationCategory=="Refugee" & cohort$LANDING_AGE %in% c(10,11,12,13,14) ))
length(which(cohort$ImmigrationCategory=="Refugee" & cohort$LANDING_AGE %in% c(15,16,17) ))

# Non-Refugees
length(which(cohort$ImmigrationCategory!="Refugee" & cohort$LANDING_AGE %in% c(0,1,2,3,4) ))
length(which(cohort$ImmigrationCategory!="Refugee" & cohort$LANDING_AGE %in% c(5,6,7,8,9) ))
length(which(cohort$ImmigrationCategory!="Refugee" & cohort$LANDING_AGE %in% c(10,11,12,13,14) ))
length(which(cohort$ImmigrationCategory!="Refugee" & cohort$LANDING_AGE %in% c(15,16,17) ))


# CMA
dfcma=cohort %>% group_by(refugeein,DESTINATION_CMA) %>% summarize(count=n())
write.csv(dfcma, "H:/Zheng_10223/ToVet/Supporting/coefcma.csv")
# World Area 
dfarea=cohort %>% group_by(refugeein,WORLD_AREA_BIRTH) %>% summarize(count=n())
write.csv(dfarea, "H:/Zheng_10223/ToVet/Supporting/coefarea.csv")
# Enclave 
dfenclave=cohort %>% group_by(refugeein, enclave) %>% summarize(count=n())
write.csv(dfenclave,"H:/Zheng_10223/ToVet/Supporting/coefenclave.csv")
# Language 
dflang=cohort %>% group_by(refugeein, AnyEnglish_Main) %>% summarize(count=n())
write.csv(dflang,"H:/Zheng_10223/ToVet/Supporting/coeflang.csv")
# Intended occ:
dfocc=cohort %>% group_by(refugeein,IntendedOccupation_Main) %>% summarize(count=n())
write.csv(dfocc,"H:/Zheng_10223/ToVet/Supporting/coefocc.csv")






#############################################################################

# P50 ##########################

#### FIGURE 2: COEF PLOT (absolute upward mobility) ####
## INDIVIDUAL
refugee <- cohort[which(cohort$ImmigrationCategory=="Refugee"),]
IGM_refugee <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$ImmigrationCategory=="Refugee"),])

IGM_age0_4 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$LANDING_AGE %in% c(0,1,2,3,4)),])
IGM_age5_9 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$LANDING_AGE %in% c(5,6,7,8,9)),])
IGM_age10_14 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$LANDING_AGE %in% c(10,11,12,13,14)),])
IGM_age15_17 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$LANDING_AGE %in% c(15,16,17)),])

IGM_english <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$AnyEnglish_Main==1),])
IGM_noenglish <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$AnyEnglish_Main==0),])

IGM_manager <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$IntendedOccupation_Main=="Managerial/Professional"),])
IGM_skilled <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$IntendedOccupation_Main=="Skilled and Technical"),])
IGM_clerical <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$IntendedOccupation_Main=="Clerical and Laborers"),])
IGM_newworker <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$IntendedOccupation_Main=="New Workers"),])
IGM_nonworker <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$IntendedOccupation_Main=="Non-Workers"),])

IGM_europe <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$WORLD_AREA_BIRTH=="Europe"),])
IGM_easternasia <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$WORLD_AREA_BIRTH=="Eastern Asia"),])
IGM_africa <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$WORLD_AREA_BIRTH=="Africa and Middle East"),])
IGM_southamerica <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$WORLD_AREA_BIRTH=="South and Central America"),])
IGM_southasia <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$WORLD_AREA_BIRTH=="Southern Asia"),])
IGM_oceania <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$WORLD_AREA_BIRTH=="Oceania and other Asia"),])

IGM_noenclave <-lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$enclave==0),])
IGM_enclave <-lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$enclave==1),])


IGM_toronto <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$DESTINATION_CMA=="Toronto"),])
IGM_montreal <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$DESTINATION_CMA=="Montreal"),])
IGM_vancouver <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$DESTINATION_CMA=="Vancouver"),])
IGM_calgary <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$DESTINATION_CMA=="Calgary"),])
IGM_edmonton <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$DESTINATION_CMA=="Edmonton"),])

output <- rbind(predict(IGM_refugee, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_age0_4, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_age5_9, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_age10_14, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_age15_17, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_noenglish, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_english, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_nonworker, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_newworker, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_clerical, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_skilled, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_manager, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_europe, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_southamerica, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_oceania, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_africa, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_southasia, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_easternasia, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_noenclave, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_enclave, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                
                predict(IGM_calgary, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                
                predict(IGM_edmonton, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_vancouver, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_toronto, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                predict(IGM_montreal, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"))

others <- cohort[which(!cohort$ImmigrationCategory=="Refugee"),]
IGM_others <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others)

IGM_age0_4 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$LANDING_AGE %in% c(0,1,2,3,4)),])
IGM_age5_9 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$LANDING_AGE %in% c(5,6,7,8,9)),])
IGM_age10_14 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$LANDING_AGE %in% c(10,11,12,13,14)),])
IGM_age15_17 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$LANDING_AGE %in% c(15,16,17)),])

IGM_english <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$AnyEnglish_Main==1),])
IGM_noenglish <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$AnyEnglish_Main==0),])

IGM_manager <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$IntendedOccupation_Main=="Managerial/Professional"),])
IGM_skilled <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$IntendedOccupation_Main=="Skilled and Technical"),])
IGM_clerical <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$IntendedOccupation_Main=="Clerical and Laborers"),])
IGM_newworker <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$IntendedOccupation_Main=="New Workers"),])
IGM_nonworker <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$IntendedOccupation_Main=="Non-Workers"),])

IGM_europe <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$WORLD_AREA_BIRTH=="Europe"),])
IGM_easternasia <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$WORLD_AREA_BIRTH=="Eastern Asia"),])
IGM_africa <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$WORLD_AREA_BIRTH=="Africa and Middle East"),])
IGM_southamerica <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$WORLD_AREA_BIRTH=="South and Central America"),])
IGM_southasia <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$WORLD_AREA_BIRTH=="Southern Asia"),])
IGM_oceania <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$WORLD_AREA_BIRTH=="Oceania and other Asia"),])


IGM_noenclave <-lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$enclave==0),])
IGM_enclave <-lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$enclave==1),])


IGM_toronto <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$DESTINATION_CMA=="Toronto"),])
IGM_montreal <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$DESTINATION_CMA=="Montreal"),])
IGM_vancouver <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$DESTINATION_CMA=="Vancouver"),])
IGM_calgary <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$DESTINATION_CMA=="Calgary"),])
IGM_edmonton <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$DESTINATION_CMA=="Edmonton"),])

output_others <- rbind(predict(IGM_others, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_age0_4, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_age5_9, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_age10_14, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_age15_17, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_noenglish, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_english, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_nonworker, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_newworker, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_clerical, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_skilled, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_manager, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_europe, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_southamerica, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_oceania, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_africa, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_southasia, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_easternasia, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_noenclave, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_enclave, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       
                       predict(IGM_calgary, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_edmonton, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_vancouver, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_toronto, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"),
                       predict(IGM_montreal, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=50), interval="confidence"))

par(mar=c(4,19,1,1))
plot(x=output[,1], y=c(1, 3:6, 8:9, 11:15, 17:22, 24:25, 27:31), xlim=c(47.5,62.8), xlab="Child Rank | Parent=p50", ylab="", yaxt="n",  cex.lab=1.5, cex.axis=1.5,
     pch=c(19, 20,20,20,20, 23,23, 18,18,18,18,18, 15,15,15,15,15,15, 12,12, 17,17,17,17,17), cex=c(1.3,2,2,2,2,1.3,1.3,2,2,2,2,2,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3),
     col=c("black", rep("firebrick",4), rep("black", 2), rep("orange", 5), rep("forestgreen", 6),rep("purple",2), rep("royalblue3", 5)))
arrows(y0=c(1, 3:6, 8:9, 11:15, 17:22,24:25, 27:31), y1=c(1, 3:6, 8:9, 11:15, 17:22,24:25, 27:31), x0=output[,2], x1=output[,3], length=0, 
       col=c("black", rep("firebrick",4), rep("black", 2), rep("orange", 5), rep("forestgreen", 6),rep("purple",2), rep("royalblue3", 5)))
points(x=output_others[,1], y=c(1, 3:6, 8:9, 11:15, 17:22,24:25, 27:31), xlim=c(42,67),xlab="", ylab="", yaxt="n",  cex.lab=1.5, cex.axis=1.5,
       pch=c(19, 20,20,20,20, 23,23, 18,18,18,18,18, 15,15,15,15,15,15, 12,12, 17,17,17,17,17), cex=c(1.3,2,2,2,2,1.3,1.3,2,2,2,2,2,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3),
       col=c(alpha("black",0.3), rep(alpha("firebrick",0.3), 4), rep(alpha("black", 0.3), 2), rep(alpha("orange", 0.3), 5), rep(alpha("forestgreen", 0.3), 6), rep(alpha("purple", 0.3), 2), rep(alpha("royalblue3", 0.3), 5)))
arrows(y0=c(1, 3:6, 8:9, 11:15, 17:22,24:25, 27:31), y1=c(1, 3:6, 8:9, 11:15, 17:22,24:25, 27:31), x0=output_others[,2], x1=output_others[,3], length=0, 
       col=c(alpha("black",0.3), rep(alpha("firebrick",0.3), 4), rep(alpha("black", 0.3), 2), rep(alpha("orange", 0.3), 5), rep(alpha("forestgreen", 0.3), 6), rep(alpha("purple", 0.3), 2), rep(alpha("royalblue3", 0.3), 5)))

text(x=33.5, y=c(1, 3:6, 8:9, 11:15, 17:22, 24:25, 27:31), adj=0, cex=1.2,
     c("Overall", "Landing Age: 0-4", "Landing Age: 5-9", "Landing Age: 10-14", "Landing Age: 15-17",
       "Speak English? No", "Speak English: Yes", "Intended Occ. Non-Workers", "Intended Occ. New Workers", "Intended Occ. Clerical & Laborers","Intended Occ. Skilled & Technical",  "Intended Occ. Managerial & Professional",   
       "Birthplace: Europe", "Birthplace: South and Central America", "Birthplace: Oceania and other Asia", "Birthplace: Africa and Middle East", "Birthplace: Southern Asia", "Birthplace: Eastern Asia", "Minority Neighborhood: No","Minority Neighborhood: Yes",
       "Landing CMA: Calgary", "Landing CMA: Edmonton", "Landing CMA: Vancouver", "Landing CMA: Toronto", "Landing CMA: Montreal"), xpd=TRUE)
text(x=output[1,1], y=1.5, "Refugee")
text(x=output_others[1,1]+1, y=1.5, "Non-Refugee", col=alpha("black", 0.4))

# P75 ################### 

#### FIGURE 2: COEF PLOT (absolute upward mobility) ####
## INDIVIDUAL
refugee <- cohort[which(cohort$ImmigrationCategory=="Refugee"),]
IGM_refugee <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$ImmigrationCategory=="Refugee"),])

IGM_age0_4 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$LANDING_AGE %in% c(0,1,2,3,4)),])
IGM_age5_9 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$LANDING_AGE %in% c(5,6,7,8,9)),])
IGM_age10_14 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$LANDING_AGE %in% c(10,11,12,13,14)),])
IGM_age15_17 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$LANDING_AGE %in% c(15,16,17)),])

IGM_english <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$AnyEnglish_Main==1),])
IGM_noenglish <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$AnyEnglish_Main==0),])

IGM_manager <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$IntendedOccupation_Main=="Managerial/Professional"),])
IGM_skilled <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$IntendedOccupation_Main=="Skilled and Technical"),])
IGM_clerical <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$IntendedOccupation_Main=="Clerical and Laborers"),])
IGM_newworker <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$IntendedOccupation_Main=="New Workers"),])
IGM_nonworker <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$IntendedOccupation_Main=="Non-Workers"),])

IGM_europe <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$WORLD_AREA_BIRTH=="Europe"),])
IGM_easternasia <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$WORLD_AREA_BIRTH=="Eastern Asia"),])
IGM_africa <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$WORLD_AREA_BIRTH=="Africa and Middle East"),])
IGM_southamerica <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$WORLD_AREA_BIRTH=="South and Central America"),])
IGM_southasia <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$WORLD_AREA_BIRTH=="Southern Asia"),])
IGM_oceania <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$WORLD_AREA_BIRTH=="Oceania and other Asia"),])

IGM_noenclave <-lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$enclave==0),])
IGM_enclave <-lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$enclave==1),])


IGM_toronto <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$DESTINATION_CMA=="Toronto"),])
IGM_montreal <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$DESTINATION_CMA=="Montreal"),])
IGM_vancouver <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$DESTINATION_CMA=="Vancouver"),])
IGM_calgary <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$DESTINATION_CMA=="Calgary"),])
IGM_edmonton <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=refugee[which(refugee$DESTINATION_CMA=="Edmonton"),])

output <- rbind(predict(IGM_refugee, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_age0_4, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_age5_9, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_age10_14, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_age15_17, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_noenglish, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_english, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_nonworker, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_newworker, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_clerical, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_skilled, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_manager, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_europe, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_southamerica, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_oceania, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_africa, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_southasia, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_easternasia, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_noenclave, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_enclave, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                
                predict(IGM_calgary, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                
                predict(IGM_edmonton, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_vancouver, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_toronto, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                predict(IGM_montreal, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"))

others <- cohort[which(!cohort$ImmigrationCategory=="Refugee"),]
IGM_others <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others)

IGM_age0_4 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$LANDING_AGE %in% c(0,1,2,3,4)),])
IGM_age5_9 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$LANDING_AGE %in% c(5,6,7,8,9)),])
IGM_age10_14 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$LANDING_AGE %in% c(10,11,12,13,14)),])
IGM_age15_17 <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$LANDING_AGE %in% c(15,16,17)),])

IGM_english <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$AnyEnglish_Main==1),])
IGM_noenglish <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$AnyEnglish_Main==0),])

IGM_manager <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$IntendedOccupation_Main=="Managerial/Professional"),])
IGM_skilled <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$IntendedOccupation_Main=="Skilled and Technical"),])
IGM_clerical <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$IntendedOccupation_Main=="Clerical and Laborers"),])
IGM_newworker <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$IntendedOccupation_Main=="New Workers"),])
IGM_nonworker <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$IntendedOccupation_Main=="Non-Workers"),])

IGM_europe <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$WORLD_AREA_BIRTH=="Europe"),])
IGM_easternasia <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$WORLD_AREA_BIRTH=="Eastern Asia"),])
IGM_africa <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$WORLD_AREA_BIRTH=="Africa and Middle East"),])
IGM_southamerica <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$WORLD_AREA_BIRTH=="South and Central America"),])
IGM_southasia <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$WORLD_AREA_BIRTH=="Southern Asia"),])
IGM_oceania <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$WORLD_AREA_BIRTH=="Oceania and other Asia"),])


IGM_noenclave <-lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$enclave==0),])
IGM_enclave <-lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$enclave==1),])


IGM_toronto <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$DESTINATION_CMA=="Toronto"),])
IGM_montreal <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$DESTINATION_CMA=="Montreal"),])
IGM_vancouver <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$DESTINATION_CMA=="Vancouver"),])
IGM_calgary <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$DESTINATION_CMA=="Calgary"),])
IGM_edmonton <- lm(Child_Income_IND_30_34_pct~MainParent_Income_HH_MainParentAge45_49_pctparent, data=others[which(others$DESTINATION_CMA=="Edmonton"),])

output_others <- rbind(predict(IGM_others, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_age0_4, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_age5_9, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_age10_14, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_age15_17, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_noenglish, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_english, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_nonworker, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_newworker, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_clerical, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_skilled, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_manager, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_europe, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_southamerica, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_oceania, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_africa, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_southasia, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_easternasia, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_noenclave, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_enclave, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       
                       predict(IGM_calgary, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_edmonton, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_vancouver, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_toronto, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"),
                       predict(IGM_montreal, newdata=data.frame("MainParent_Income_HH_MainParentAge45_49_pctparent"=75), interval="confidence"))

par(mar=c(4,19,1,1))
plot(x=output[,1], y=c(1, 3:6, 8:9, 11:15, 17:22, 24:25, 27:31), xlim=c(53,68.5), xlab="Child Rank | Parent=p75", ylab="", yaxt="n",  cex.lab=1.5, cex.axis=1.5,
     pch=c(19, 20,20,20,20, 23,23, 18,18,18,18,18, 15,15,15,15,15,15, 12,12, 17,17,17,17,17), cex=c(1.3,2,2,2,2,1.3,1.3,2,2,2,2,2,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3),
     col=c("black", rep("firebrick",4), rep("black", 2), rep("orange", 5), rep("forestgreen", 6),rep("purple",2), rep("royalblue3", 5)))
arrows(y0=c(1, 3:6, 8:9, 11:15, 17:22,24:25, 27:31), y1=c(1, 3:6, 8:9, 11:15, 17:22,24:25, 27:31), x0=output[,2], x1=output[,3], length=0, 
       col=c("black", rep("firebrick",4), rep("black", 2), rep("orange", 5), rep("forestgreen", 6),rep("purple",2), rep("royalblue3", 5)))
points(x=output_others[,1], y=c(1, 3:6, 8:9, 11:15, 17:22,24:25, 27:31), xlim=c(42,67),xlab="", ylab="", yaxt="n",  cex.lab=1.5, cex.axis=1.5,
       pch=c(19, 20,20,20,20, 23,23, 18,18,18,18,18, 15,15,15,15,15,15, 12,12, 17,17,17,17,17), cex=c(1.3,2,2,2,2,1.3,1.3,2,2,2,2,2,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3,1.3),
       col=c(alpha("black",0.3), rep(alpha("firebrick",0.3), 4), rep(alpha("black", 0.3), 2), rep(alpha("orange", 0.3), 5), rep(alpha("forestgreen", 0.3), 6), rep(alpha("purple", 0.3), 2), rep(alpha("royalblue3", 0.3), 5)))
arrows(y0=c(1, 3:6, 8:9, 11:15, 17:22,24:25, 27:31), y1=c(1, 3:6, 8:9, 11:15, 17:22,24:25, 27:31), x0=output_others[,2], x1=output_others[,3], length=0, 
       col=c(alpha("black",0.3), rep(alpha("firebrick",0.3), 4), rep(alpha("black", 0.3), 2), rep(alpha("orange", 0.3), 5), rep(alpha("forestgreen", 0.3), 6), rep(alpha("purple", 0.3), 2), rep(alpha("royalblue3", 0.3), 5)))

text(x=38.8, y=c(1, 3:6, 8:9, 11:15, 17:22, 24:25, 27:31), adj=0, cex=1.2,
     c("Overall", "Landing Age: 0-4", "Landing Age: 5-9", "Landing Age: 10-14", "Landing Age: 15-17",
       "Speak English? No", "Speak English: Yes", "Intended Occ. Non-Workers", "Intended Occ. New Workers", "Intended Occ. Clerical & Laborers","Intended Occ. Skilled & Technical",  "Intended Occ. Managerial & Professional",   
       "Birthplace: Europe", "Birthplace: South and Central America", "Birthplace: Oceania and other Asia", "Birthplace: Africa and Middle East", "Birthplace: Southern Asia", "Birthplace: Eastern Asia", "Minority Neighborhood: No","Minority Neighborhood: Yes",
       "Landing CMA: Calgary", "Landing CMA: Edmonton", "Landing CMA: Vancouver", "Landing CMA: Toronto", "Landing CMA: Montreal"), xpd=TRUE)
text(x=output[1,1]-1.2, y=1.5, "Refugee")
text(x=output_others[1,1]+1.4, y=1.5, "Non-Refugee", col=alpha("black", 0.4))



####################################### Counts: 
c(dim(refugee)[1], 
  dim(refugee[which(refugee$LANDING_AGE %in% c(0,1,2,3,4)),])[1], dim(refugee[which(refugee$LANDING_AGE %in% c(5,6,7,8,9)),])[1], dim(refugee[which(refugee$LANDING_AGE %in% c(10,11,12,13,14)),])[1], dim(refugee[which(refugee$LANDING_AGE %in% c(15,16,17)),])[1],
  dim(refugee[which(refugee$AnyEnglish==1),])[1],dim(refugee[which(refugee$AnyEnglish==0),])[1],
  dim(refugee[which(refugee$IntendedOccupation=="Managerial/Professional"),])[1],dim(refugee[which(refugee$IntendedOccupation=="Skilled and Technical"),])[1], dim(refugee[which(refugee$IntendedOccupation=="Clerical and Laborers"),])[1], dim(refugee[which(refugee$IntendedOccupation=="New Workers"),])[1], dim(refugee[which(refugee$IntendedOccupation=="Non-Workers"),])[1],
  
  dim(refugee[which(refugee$WORLD_AREA_BIRTH=="Europe"),])[1], dim(refugee[which(refugee$WORLD_AREA_BIRTH=="Eastern Asia"),])[1], dim(refugee[which(refugee$WORLD_AREA_BIRTH=="Africa and Middle East"),])[1], dim(refugee[which(refugee$WORLD_AREA_BIRTH=="South and Central America"),])[1], dim(refugee[which(refugee$WORLD_AREA_BIRTH=="Southern Asia"),])[1], dim(refugee[which(refugee$WORLD_AREA_BIRTH=="Oceania and other Asia"),])[1],
  
  dim(refugee[which(refugee$DESTINATION_CMA=="Toronto"),])[1], dim(refugee[which(refugee$DESTINATION_CMA=="Montreal"),])[1], dim(refugee[which(refugee$DESTINATION_CMA=="Vancouver"),])[1], dim(refugee[which(refugee$DESTINATION_CMA=="Calgary"),])[1], dim(refugee[which(refugee$DESTINATION_CMA=="Edmonton"),])[1])

c(dim(others)[1], 
  dim(others[which(others$LANDING_AGE %in% c(0,1,2,3,4)),])[1], dim(others[which(others$LANDING_AGE %in% c(5,6,7,8,9)),])[1], dim(others[which(others$LANDING_AGE %in% c(10,11,12,13,14)),])[1], dim(others[which(others$LANDING_AGE %in% c(15,16,17)),])[1],
  dim(others[which(others$AnyEnglish==1),])[1],dim(others[which(others$AnyEnglish==0),])[1],
  dim(others[which(others$IntendedOccupation=="Managerial/Professional"),])[1],dim(others[which(others$IntendedOccupation=="Skilled and Technical"),])[1], dim(others[which(others$IntendedOccupation=="Clerical and Laborers"),])[1], dim(others[which(others$IntendedOccupation=="New Workers"),])[1], dim(others[which(others$IntendedOccupation=="Non-Workers"),])[1],
  
  dim(others[which(others$WORLD_AREA_BIRTH=="Europe"),])[1], dim(others[which(others$WORLD_AREA_BIRTH=="Eastern Asia"),])[1], dim(others[which(others$WORLD_AREA_BIRTH=="Africa and Middle East"),])[1], dim(others[which(others$WORLD_AREA_BIRTH=="South and Central America"),])[1], dim(others[which(others$WORLD_AREA_BIRTH=="Southern Asia"),])[1], dim(others[which(others$WORLD_AREA_BIRTH=="Oceania and other Asia"),])[1],
  
  dim(others[which(others$DESTINATION_CMA=="Toronto"),])[1], dim(others[which(others$DESTINATION_CMA=="Montreal"),])[1], dim(others[which(others$DESTINATION_CMA=="Vancouver"),])[1], dim(others[which(others$DESTINATION_CMA=="Calgary"),])[1], dim(others[which(others$DESTINATION_CMA=="Edmonton"),])[1])

